Skip to content

Instrumentation Patch Removal and SPI AWS SDK Test Addition #1120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 13, 2025

Conversation

anahatAWS
Copy link
Contributor

This is the final PR for the SPI aws-sdk instrumentation. It removes the opentelemetry-java-instrumentation patch and adds comprehensive unit test coverage for AWS experimental attributes in both AWS SDK v1.11 and v2.2 instrumentation packages. The v2.2 package introduces 29 new experimental attributes while v1.11 adds 23 new experimental attributes. All attributes are now tested through unit tests and/or contract tests.

Description of changes:

AWS SDK v2.2 (awssdk_v2_2)

New attributes being tested:

  1. AWS_BUCKET_NAME - testS3ExperimentalAttributes() & contract tests
  2. AWS_QUEUE_URL - testSqsExperimentalAttributes() & contract tests
  3. AWS_QUEUE_NAME - contract tests
  4. AWS_STREAM_NAME - testKinesisExperimentalAttributes() & contract tests
  5. AWS_STREAM_ARN - testKinesisExperimentalAttributes() & contract tests
  6. AWS_TABLE_NAME - testDynamoDbExperimentalAttributes()
  7. AWS_GUARDRAIL_ID - contract tests
  8. AWS_GUARDRAIL_ARN - contract tests
  9. AWS_AGENT_ID - testBedrockAgentExperimentalAttributes() & contract tests
  10. AWS_DATA_SOURCE_ID - testBedrockDataSourceExperimentalAttributes() & contract tests
  11. AWS_KNOWLEDGE_BASE_ID - testBedrockKnowledgeBaseExperimentalAttributes() & contract tests
  12. GEN_AI_MODEL - testBedrockExperimentalAttributes() & contract tests
  13. GEN_AI_SYSTEM - contract tests
  14. GEN_AI_REQUEST_MAX_TOKENS - testBedrockExperimentalAttributes() & contract tests
  15. GEN_AI_REQUEST_TEMPERATURE - testBedrockExperimentalAttributes() & contract tests
  16. GEN_AI_REQUEST_TOP_P - contract tests
  17. GEN_AI_RESPONSE_FINISH_REASONS - contract tests
  18. GEN_AI_USAGE_INPUT_TOKENS - contract tests
  19. GEN_AI_USAGE_OUTPUT_TOKENS - contract tests
  20. AWS_STATE_MACHINE_ARN - testStepFunctionExperimentalAttributes() & contract tests
  21. AWS_STEP_FUNCTIONS_ACTIVITY_ARN - testStepFunctionExperimentalAttributes() & contract tests
  22. AWS_SNS_TOPIC_ARN - testSnsExperimentalAttributes() & contract tests
  23. AWS_SECRET_ARN - testSecretsManagerExperimentalAttributes() & contract tests
  24. AWS_LAMBDA_NAME - testLambdaExperimentalAttributes()
  25. AWS_LAMBDA_ARN - testLambdaArnExperimentalAttribute()
  26. AWS_LAMBDA_RESOURCE_ID - testLambdaResourceIdExperimentalAttribute()
  27. AWS_TABLE_ARN - testTableArnExperimentalAttribute()
  28. AWS_AUTH_ACCESS_KEY - testAuthAccessKeyExperimentalAttribute()
  29. AWS_AUTH_REGION - testAuthRegionExperimentalAttribute()
  • Tests leverage AWS SDK v2's getValueForField() API for clean, mockable attribute extraction
  • Includes comprehensive testing for:
    • Core AWS services (S3, DynamoDB, SQS, SNS, Kinesis, Lambda, Step Functions, Secrets Manager)
    • Bedrock Gen AI attributes with JSON parsing validation
    • Bedrock resource attributes (Agent, Knowledge Base, Data Source)
    • Authentication attributes (access key, region)

AWS SDK v1.11 (awssdk_v1_11)

New attributes being tested:

  1. AWS_STREAM_ARN - testKinesisExperimentalAttributes() & contract tests
  2. AWS_TABLE_ARN - testTableArnExperimentalAttributes() (Service identification only)
  3. AWS_AGENT_ID - contract tests
  4. AWS_KNOWLEDGE_BASE_ID - contract tests
  5. AWS_DATA_SOURCE_ID - contract tests
  6. AWS_GUARDRAIL_ID - testBedrockGuardrailAttributes() (Service identification only) & contract tests
  7. AWS_GUARDRAIL_ARN - testBedrockGuardrailAttributes() (Service identification only) & contract tests
  8. AWS_BEDROCK_RUNTIME_MODEL_ID - testBedrockRuntimeAttributes() (Service identification only) & contract tests
  9. AWS_BEDROCK_SYSTEM - contract tests
  10. GEN_AI_REQUEST_MAX_TOKENS - contract tests
  11. GEN_AI_REQUEST_TEMPERATURE - contract tests
  12. GEN_AI_REQUEST_TOP_P - contract tests
  13. GEN_AI_RESPONSE_FINISH_REASONS - contract tests
  14. GEN_AI_USAGE_INPUT_TOKENS - contract tests
  15. GEN_AI_USAGE_OUTPUT_TOKENS - contract tests
  16. AWS_STATE_MACHINE_ARN - testStepFunctionsExperimentalAttributes() & contract tests
  17. AWS_STEP_FUNCTIONS_ACTIVITY_ARN - contract tests
  18. AWS_SNS_TOPIC_ARN - testSnsExperimentalAttributes() & contract tests
  19. AWS_SECRET_ARN - testSecretsManagerExperimentalAttributes() (Service identification only) & contract tests
  20. AWS_LAMBDA_NAME - testLambdaNameExperimentalAttributes()
  21. AWS_LAMBDA_ARN - testLambdaArnExperimentalAttributes()
  22. AWS_LAMBDA_RESOURCE_ID - testLambdaResourceIdExperimentalAttributes() (Service identification only)
  23. AWS_AUTH_ACCESS_KEY - testAuthAccessKeyAttributes()

V1.11 is harder to test:

V1.11 uses Java reflection to dynamically find and call methods like getFunctionName() on AWS request objects at runtime. This creates several testing challenges:

  • Mock Method Mismatch: When you mock an AWS request object, it doesn't have the actual methods that reflection is trying to find. The reflection silently fails and returns null, making tests pass even though no attributes were extracted.
  • Class Dependencies: To test properly, you'd need real AWS SDK classes instead of mocks, creating tight coupling between tests and external dependencies.
  • Nested Object Complexity: Many attributes require traversing nested properties, which means mocking entire object graphs with proper method chains.

Contract tests sidestep these issues by using real AWS SDK objects against LocalStack, testing the complete end-to-end flow including actual reflection behavior without the complexity of mocking Java's reflection system.

Related

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@anahatAWS anahatAWS requested a review from a team as a code owner July 25, 2025 18:59
@anahatAWS
Copy link
Contributor Author

Due to change in dependencyManagement otelVersion here, lambda-layer patch file aws-otel-java-instrumentation.patch has been updated. Also, because we removed the instrumentation patch that changed the upstream version.gradle.kts version names here, we need to update lambda-layer patch file opentelemetry-java-instrumentation (which builds off of original patch version) as well.

@srprash srprash changed the title Instrumentation Patch Removal and SPI AWS SDK Test Addition [DO NOT MERGE] Instrumentation Patch Removal and SPI AWS SDK Test Addition Aug 4, 2025
@anahatAWS anahatAWS changed the title [DO NOT MERGE] Instrumentation Patch Removal and SPI AWS SDK Test Addition Instrumentation Patch Removal and SPI AWS SDK Test Addition Aug 13, 2025
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.60%. Comparing base (09e6487) to head (ee20ca8).
⚠️ Report is 456 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff              @@
##               main    #1120       +/-   ##
=============================================
- Coverage     85.71%   67.60%   -18.11%     
- Complexity       19      500      +481     
=============================================
  Files             3       53       +50     
  Lines            49     2584     +2535     
  Branches          5      348      +343     
=============================================
+ Hits             42     1747     +1705     
- Misses            3      711      +708     
- Partials          4      126      +122     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bjrara bjrara merged commit 25b2cd8 into aws-observability:main Aug 13, 2025
7 of 10 checks passed
anahatAWS added a commit to anahatAWS/aws-otel-java-instrumentation that referenced this pull request Aug 14, 2025
…rvability#1120)

This is the final PR for the SPI aws-sdk instrumentation. It removes the
[opentelemetry-java-instrumentation](https://github.com/aws-observability/aws-otel-java-instrumentation/blob/main/.github/patches/opentelemetry-java-instrumentation.patch)
patch and adds comprehensive unit test coverage for AWS experimental
attributes in both AWS SDK v1.11 and v2.2 instrumentation packages. The
v2.2 package introduces 29 new experimental attributes while v1.11 adds
23 new experimental attributes. All attributes are now tested through
unit tests and/or contract tests.

### Description of changes:

#### AWS SDK v2.2 (awssdk_v2_2)
New attributes being tested:
1. AWS_BUCKET_NAME - testS3ExperimentalAttributes() & contract tests
2. AWS_QUEUE_URL - testSqsExperimentalAttributes() & contract tests
3. AWS_QUEUE_NAME - contract tests
4. AWS_STREAM_NAME - testKinesisExperimentalAttributes() & contract
tests
5. AWS_STREAM_ARN - testKinesisExperimentalAttributes() & contract tests
6. AWS_TABLE_NAME - testDynamoDbExperimentalAttributes()
7. AWS_GUARDRAIL_ID - contract tests
8. AWS_GUARDRAIL_ARN - contract tests
9. AWS_AGENT_ID - testBedrockAgentExperimentalAttributes() & contract
tests
10. AWS_DATA_SOURCE_ID - testBedrockDataSourceExperimentalAttributes() &
contract tests
11. AWS_KNOWLEDGE_BASE_ID -
testBedrockKnowledgeBaseExperimentalAttributes() & contract tests
12. GEN_AI_MODEL - testBedrockExperimentalAttributes() & contract tests
13. GEN_AI_SYSTEM - contract tests
14. GEN_AI_REQUEST_MAX_TOKENS - testBedrockExperimentalAttributes() &
contract tests
15. GEN_AI_REQUEST_TEMPERATURE - testBedrockExperimentalAttributes() &
contract tests
16. GEN_AI_REQUEST_TOP_P - contract tests
17. GEN_AI_RESPONSE_FINISH_REASONS - contract tests
18. GEN_AI_USAGE_INPUT_TOKENS - contract tests
19. GEN_AI_USAGE_OUTPUT_TOKENS - contract tests
20. AWS_STATE_MACHINE_ARN - testStepFunctionExperimentalAttributes() &
contract tests
21. AWS_STEP_FUNCTIONS_ACTIVITY_ARN -
testStepFunctionExperimentalAttributes() & contract tests
22. AWS_SNS_TOPIC_ARN - testSnsExperimentalAttributes() & contract tests
23. AWS_SECRET_ARN - testSecretsManagerExperimentalAttributes() &
contract tests
24. AWS_LAMBDA_NAME - testLambdaExperimentalAttributes()
25. AWS_LAMBDA_ARN - testLambdaArnExperimentalAttribute()
26. AWS_LAMBDA_RESOURCE_ID - testLambdaResourceIdExperimentalAttribute()
27. AWS_TABLE_ARN - testTableArnExperimentalAttribute()
28. AWS_AUTH_ACCESS_KEY - testAuthAccessKeyExperimentalAttribute()
29. AWS_AUTH_REGION - testAuthRegionExperimentalAttribute()

- Tests leverage AWS SDK v2's getValueForField() API for clean, mockable
attribute extraction
- Includes comprehensive testing for:
- Core AWS services (S3, DynamoDB, SQS, SNS, Kinesis, Lambda, Step
Functions, Secrets Manager)
     - Bedrock Gen AI attributes with JSON parsing validation
     - Bedrock resource attributes (Agent, Knowledge Base, Data Source)
     - Authentication attributes (access key, region)

### AWS SDK v1.11 (awssdk_v1_11)
New attributes being tested:
1. AWS_STREAM_ARN - testKinesisExperimentalAttributes() & contract tests
2. AWS_TABLE_ARN - testTableArnExperimentalAttributes() (Service
identification only)
3. AWS_AGENT_ID - contract tests
4. AWS_KNOWLEDGE_BASE_ID - contract tests
5. AWS_DATA_SOURCE_ID - contract tests
6. AWS_GUARDRAIL_ID - testBedrockGuardrailAttributes() (Service
identification only) & contract tests
7. AWS_GUARDRAIL_ARN - testBedrockGuardrailAttributes() (Service
identification only) & contract tests
8. AWS_BEDROCK_RUNTIME_MODEL_ID - testBedrockRuntimeAttributes()
(Service identification only) & contract tests
9. AWS_BEDROCK_SYSTEM - contract tests
10. GEN_AI_REQUEST_MAX_TOKENS - contract tests
11. GEN_AI_REQUEST_TEMPERATURE - contract tests
12. GEN_AI_REQUEST_TOP_P - contract tests
13. GEN_AI_RESPONSE_FINISH_REASONS - contract tests
14. GEN_AI_USAGE_INPUT_TOKENS - contract tests
15. GEN_AI_USAGE_OUTPUT_TOKENS - contract tests
16. AWS_STATE_MACHINE_ARN - testStepFunctionsExperimentalAttributes() &
contract tests
17. AWS_STEP_FUNCTIONS_ACTIVITY_ARN - contract tests
18. AWS_SNS_TOPIC_ARN - testSnsExperimentalAttributes() & contract tests
19. AWS_SECRET_ARN - testSecretsManagerExperimentalAttributes() (Service
identification only) & contract tests
20. AWS_LAMBDA_NAME - testLambdaNameExperimentalAttributes()
21. AWS_LAMBDA_ARN - testLambdaArnExperimentalAttributes()
22. AWS_LAMBDA_RESOURCE_ID -
testLambdaResourceIdExperimentalAttributes() (Service identification
only)
23. AWS_AUTH_ACCESS_KEY - testAuthAccessKeyAttributes()

*V1.11 is harder to test:*

V1.11 uses Java reflection to dynamically find and call methods like
getFunctionName() on AWS request objects at runtime. This creates
several testing challenges:
- Mock Method Mismatch: When you mock an AWS request object, it doesn't
have the actual methods that reflection is trying to find. The
reflection silently fails and returns null, making tests pass even
though no attributes were extracted.
- Class Dependencies: To test properly, you'd need real AWS SDK classes
instead of mocks, creating tight coupling between tests and external
dependencies.
- Nested Object Complexity: Many attributes require traversing nested
properties, which means mocking entire object graphs with proper method
chains.

Contract tests sidestep these issues by using real AWS SDK objects
against LocalStack, testing the complete end-to-end flow including
actual reflection behavior without the complexity of mocking Java's
reflection system.

### Related
- PRs for aws-sdk v1.11: aws-observability#1115 and aws-observability#1117
- PRs for aws-sdk v2.2: aws-observability#1111 and aws-observability#1113
- Replaces patch: [current
patch](https://github.com/aws-observability/aws-otel-java-instrumentation/blob/main/.github/patches/opentelemetry-java-instrumentation.patch)

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
# Conflicts:
#	.github/patches/opentelemetry-java-instrumentation.patch
#	dependencyManagement/build.gradle.kts
#	lambda-layer/patches/aws-otel-java-instrumentation.patch
#	lambda-layer/patches/opentelemetry-java-instrumentation.patch
@anahatAWS anahatAWS mentioned this pull request Aug 14, 2025
liustve added a commit that referenced this pull request Aug 14, 2025
*Description of changes:*

Merges changes from mainline to v2.11.3
Namely: #1111 #1115 #1113 #1117 and #1120  

Steps followed:

1. Fork `aws-otel-java-instrumentation` repo
2. Checkout `release/2.11.x`
3. Create branch `release/2.11.3` based off `release/2.11.x` (`git
checkout -b release/2.11.3`)
4. `git cherry-pick 572215e ac3c0c7 9a76dda 8a3b772 25b2cd8`
5. Resolved merge conflict for 25b2cd8
6. run `./gradlew dependencyUpdates`
7. Create PR

```
The following dependencies are using the latest release version:
 - com.sparkjava:spark-core:2.9.4
 - io.opentelemetry:opentelemetry-extension-aws:1.20.1

The following dependencies have later release versions:
 - com.amazonaws:aws-java-sdk-bom [1.12.599 -> 1.12.788]
     https://aws.amazon.com/sdkforjava
 - com.fasterxml.jackson:jackson-bom [2.16.0 -> 2.19.2]
     https://github.com/FasterXML/jackson-bom
 - com.github.ben-manes.versions:com.github.ben-manes.versions.gradle.plugin [0.50.0 -> 0.52.0]
 - com.google.guava:guava-bom [33.0.0-jre -> 33.4.8-jre]
     https://github.com/google/guava
 - com.google.protobuf:protobuf-bom [3.25.1 -> 4.31.1]
     https://developers.google.com/protocol-buffers/
 - com.linecorp.armeria:armeria-bom [1.26.4 -> 1.33.1]
     https://armeria.dev/
 - com.squareup.okhttp3:okhttp [4.12.0 -> 5.1.0]
     https://square.github.io/okhttp/
 - commons-logging:commons-logging [1.2 -> 1.3.5]
     https://commons.apache.org/proper/commons-logging/
 - io.grpc:grpc-bom [1.59.1 -> 1.74.0]
     https://github.com/grpc/grpc-java
 - io.opentelemetry.contrib:opentelemetry-aws-resources [1.39.0-alpha -> 1.48.0-alpha]
     https://github.com/open-telemetry/opentelemetry-java-contrib
 - io.opentelemetry.contrib:opentelemetry-aws-xray [1.39.0-adot1 -> 1.48.0]
     https://github.com/open-telemetry/opentelemetry-java-contrib
 - io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha [2.11.0-alpha -> 2.18.1-alpha]
     https://github.com/open-telemetry/opentelemetry-java-instrumentation
 - io.opentelemetry.javaagent:opentelemetry-javaagent [2.11.0 -> 2.18.1]
     https://github.com/open-telemetry/opentelemetry-java-instrumentation
 - io.opentelemetry.proto:opentelemetry-proto [1.0.0-alpha -> 1.7.0-alpha]
     https://github.com/open-telemetry/opentelemetry-proto-java
 - net.bytebuddy:byte-buddy [1.14.10 -> 1.17.6]
     https://bytebuddy.net
 - org.apache.logging.log4j:log4j-bom [2.21.1 -> 2.25.1]
     https://logging.apache.org/log4j/2.x/
 - org.assertj:assertj-core [3.24.2 -> 3.27.4]
     https://assertj.github.io/doc/#assertj-core
 - org.curioswitch.curiostack:protobuf-jackson [2.2.0 -> 2.8.1]
     https://github.com/curioswitch/protobuf-jackson
 - org.junit:junit-bom [5.10.1 -> 5.13.4]
     https://junit.org/
 - org.slf4j:slf4j-api [1.7.36 -> 2.0.17]
     http://www.slf4j.org
 - org.slf4j:slf4j-simple [1.7.36 -> 2.0.17]
     http://www.slf4j.org
 - org.springframework.boot:spring-boot-dependencies [2.7.17 -> 3.5.4]
     https://spring.io/projects/spring-boot
 - org.testcontainers:testcontainers-bom [1.19.3 -> 1.21.3]
     https://java.testcontainers.org
 - software.amazon.awssdk:bom [2.30.17 -> 2.32.22]
     https://aws.amazon.com/sdkforjava

Gradle release-candidate updates:
 - Gradle: [8.10 -> 9.0.0 -> 9.1.0-rc-1]
```

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

---------

Co-authored-by: Thomas Pierce <[email protected]>
Co-authored-by: Steve Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants